package com.yj.suncity.setting;

import java.util.ArrayList;
import java.util.List;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONObject;

import com.yj.suncity.R;
import com.yj.suncity.async.AsyncTaskUtil;
import com.yj.suncity.async.AsyncTaskUtil.ResultCallBack;
import com.yj.suncity.constant.URLCon;
import com.yj.suncity.utis.ToastUtil;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;

public class FeedbackActivity extends Activity {
	private Context context;
	private EditText mEdt_jianyi, mEdt_fangshi;
	private List<NameValuePair> pairs;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_feedback);
		context = this;
		pairs = new ArrayList<NameValuePair>();
		findView();
	}

	private void findView() {
		mEdt_jianyi = (EditText) findViewById(R.id.edt_jianyi);
		mEdt_fangshi = (EditText) findViewById(R.id.edt_fangshi);

	}

	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.btnHeadBack:
			this.finish();
			break;
		case R.id.btn_submit:
			String jianyi = mEdt_jianyi.getText().toString().trim();
			String fangshi = mEdt_fangshi.getText().toString().trim();
			if (jianyi.equals("")) {
				ToastUtil.ShowToast(context, "请输入您对我们的建议！");
				return;
			}
			if (fangshi.equals("")) {
				ToastUtil.ShowToast(context, "请留下您的联系方式！");
				return;
			}
			pairs.clear();
			pairs.add(new BasicNameValuePair("action", "feedback"));
			pairs.add(new BasicNameValuePair("content", jianyi));
			pairs.add(new BasicNameValuePair("tel", fangshi));
			submitComment();

			break;
		default:
			break;
		}
	}

	private void submitComment() {
		String path = URLCon.设置;
		AsyncTaskUtil asyncTaskUtil = new AsyncTaskUtil(context, pairs, null,
				false, null, true, "正在提交......", new ResultCallBack() {
					@Override
					public void JSONResult(JSONObject jsonObject) {

						ToastUtil.ShowToast(context,
								jsonObject.optString("msg"));

					}
				});
		asyncTaskUtil.execute(path);
	}

}
